import { Logger, ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { CommonInterceptor } from './common/common.interceptor';
import { CommonFilter } from './common/common.filter';
import { CommonGuard } from './common/common.guard';
import * as dotenv from 'dotenv';
dotenv.config();
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    cors: true,
  });
  app.useGlobalInterceptors(new CommonInterceptor());
  app.useGlobalFilters(new CommonFilter())
  app.useGlobalGuards(new CommonGuard())
  app.useGlobalPipes(new ValidationPipe())
  // 配置 CORS
  app.enableCors({
    origin: '*', // 允许的域名
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    credentials: true,
    allowedHeaders: 'token,Content-Type',
  });
  Logger.log('listing in http://localhost:3333');
  await app.listen(process.env.PORT ?? 3333);
}
bootstrap();
